#!/usr/bin/env python

# Usage
# ./<program> <ceaser text> <path_to_wordlist>
# apt-get install iamerican-insane

import sys,re
text = sys.argv[1].lower()
wordlist = sys.argv[2]

def searchforword(w):
  with open(wordlist) as f:
    for _ in f:
      if re.search("^%s$"%(w),_):
        return True
    return False

def ceaser_shift(x,shift):
  withshift =  x+shift
  if withshift > 122:
    rem = withshift - 122
    return rem + 96
  return withshift


for alpha in range(26):
  lst = []
  for a in text: 
    if a == " ":
      lst.append(32)
    else:
      lst.append(ceaser_shift(ord(a),alpha))

  returnlist = map(lambda x: chr(x),lst)
  fullpara = ''.join(map(str, returnlist))
  grablist =  filter(searchforword,fullpara.split())
  if len(grablist) == len(fullpara.split()):
    print fullpara



